package com.feng.gaoerfu.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.feng.gaoerfu.R;
import com.feng.gaoerfu.bean.BallPersonData;
import com.feng.gaoerfu.bean.TableData;
import com.feng.gaoerfu.bean.TitleData;

import java.util.ArrayList;

import static com.feng.gaoerfu.base.App.mContext;

/**
 * @time 2017/8/29 0029 16:57
 */

public class MyTableAdapter extends TableAdapter {

    public MyTableAdapter(ArrayList<TitleData> firstTitleData, ArrayList<BallPersonData> ballPersonData, ArrayList<ArrayList<TableData>> tableData) {
        super(firstTitleData, ballPersonData, tableData);
    }

    @Override
    public View getTitleView(int position, TitleData data) {
        View titleView = View.inflate(mContext, R.layout.item_title_view, null);
        titleView.setBackgroundColor(mContext.getResources().getColor(R.color.light_gray2));
        TextView tvBall = (TextView) titleView.findViewById(R.id.title_tv_ball_num);
        TextView tvGanNum = (TextView) titleView.findViewById(R.id.title_tv_gan_num);
        tvBall.setText(data.ballNum + "");
        tvGanNum.setText(data.ganNum + "");
        return titleView;
    }

    @Override
    public View getColumnView(int position, BallPersonData data) {
        View columnView = View.inflate(mContext, R.layout.item_column_view, null);
        columnView.setBackgroundColor(mContext.getResources().getColor(R.color.light_gray2));
        TextView tvTame = (TextView) columnView.findViewById(R.id.tv_column_name);
        ImageView iv = (ImageView) columnView.findViewById(R.id.iv_column);
        ImageView ivBall = (ImageView) columnView.findViewById(R.id.iv_ball);
        tvTame.setText(data.name);
        iv.setImageResource(data.drawable);
//        ivBall.setImageResource(data.ballColor);
        return columnView;
    }

    @Override
    public View getTableView(int x, int y, TableData data) {
        View tableView = View.inflate(mContext, R.layout.item_table_view, null);

        TextView tvYardNum = (TextView) tableView.findViewById(R.id.tv_table_yard_num);
        LinearLayout layoutHasData = (LinearLayout) tableView.findViewById(R.id.layout_has_data);
        TextView tvGanNum = (TextView) tableView.findViewById(R.id.tv_table_gan_num);
        TextView tvTuiNum = (TextView) tableView.findViewById(R.id.tv_table_tui_num);
        TextView tvErrorNum = (TextView) tableView.findViewById(R.id.tv_table_error);
//        if (data.numOfGan != 0) {
            layoutHasData.setVisibility(View.VISIBLE);
            tvYardNum.setVisibility(View.GONE);
//        } else {
//            layoutHasData.setVisibility(View.GONE);
//            tvYardNum.setVisibility(View.VISIBLE);
//        }
        tvGanNum.setText(data.numOfGan + "");
        tvTuiNum.setText(data.numOfTui + "");
        tvYardNum.setText(data.numOfYards + "");
        tvErrorNum.setText(data.numOfError + "");

        return tableView;
    }
}
